import { DynamicLike } from '@/entity/dynamic-like.entity';
import { Dynamic } from '@/entity/dynamic.entity';
import { StudyMatchResult } from '@/entity/study-match-result.entity';
import { User } from '@/entity/user.entity';
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';

@Injectable()
export class HomeService {
  constructor(
    @InjectRepository(Dynamic)
    private readonly dynamicRepository: Repository<Dynamic>,
    @InjectRepository(User)
    private readonly userRepository: Repository<User>,
    @InjectRepository(DynamicLike)
    private readonly dynamicLikeRepository: Repository<DynamicLike>,
    @InjectRepository(StudyMatchResult)
    private readonly studyMatchResultRepository: Repository<StudyMatchResult>,
  ) {}

  async homeSelect() {
    // 查询总用户数
    const userCount = await this.userRepository.count({});

    // 查询总动态数
    const dynamicCount = await this.dynamicRepository.count({});

    // 查询总匹配数
    const matchCount = await this.studyMatchResultRepository.count({});

    // 查询总点赞数
    const likeCount = await this.dynamicLikeRepository.count({});

    return {
      userCount,
      dynamicCount,
      matchCount,
      likeCount,
    };
  }
}
